﻿using System;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;
using System.Collections.Generic;
///
using ScheduleMVVM.Model.Miscellaneous;
using ScheduleMVVM.Model.PersistentFramework;
using GalaSoft.MvvmLight.Messaging;


namespace ScheduleMVVM.Model.RuntimeFramework
{
    internal class AdvancedDataAccess : DataAccess
    {
        #region Private fields and logic
        protected Messenger MessengerInstance;

        protected override void NotifyCompleted()
        {
            MessengerInstance.Send<DownloadCompletedMessage>(new DownloadCompletedMessage()
                {
                    callback = this
                });
        }
        protected override void NotifyError(String Text, Exception e, ErrorCause cause)
        {
            var message = new DownloadErrorMessage()
            {
                callback = this,
                ErrorMessage = Text,
                UnderlyingException = e,
                Cause = cause
            };
            MessengerInstance.Send<DownloadErrorMessage>(message);
        }
        protected override void NotifyInvoked()
        {
            MessengerInstance.Send<DownloadInvokedMessage>(new DownloadInvokedMessage()
                {
                    callback = this
                });
        }
        #endregion
        public AdvancedDataAccess(RouteEntry favourite) : base(favourite)
        {
            MessengerInstance = Messenger.Default;
            // Cancel operation on deleting
            MessengerInstance.Register<CancelDownloadCommand>(this, delegate
            {
                this.Cancel();
            });
        }
    }    
}
